import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;

public class calProxy {
    private CalInt target;

    public calProxy(CalInt target) {
         this.target = target;
    }

    public CalInt getProxy(){
        CalInt proxy = null;
        ClassLoader loader = target.getClass().getClassLoader();
        Class [] interfaces = new Class[] {CalInt.class};
        InvocationHandler h = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                String methodName = method.getName();
                System.out.println("现在用的计算方法是"+methodName+"参数是"+ Arrays.asList(args));
                Object result = method.invoke(target,args);
                System.out.println("计算方法是"+methodName+"计算结果是"+result);
                return result;
            }
        } ;
        proxy =(CalInt) Proxy.newProxyInstance(loader,interfaces,h);
        return proxy;

    }

}
